package com.example.administrator.helloword;


import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TimePicker;
import android.widget.Toast;

import static android.support.v4.os.LocaleListCompat.create;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    findViewById(R.id.btn_diglog1).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            showSimpleDialog();
        }
    });
     }
//第一种 简单的
    private void showSimpleDialog() {
        final String[] cities={"北京","广州","上海","重庆","深圳"};
        final String[] xinbie={"男","女","不知道"};
        final String[] aihao={"睡觉","听英语","看书","代码"};
        final boolean isChecked[]=new boolean[4];
        //定义一个输入框
        final EditText editText1=new EditText(MainActivity.this);

        View view= LayoutInflater.from(MainActivity.this)
                .inflate(R.layout.dialog_input,null,false);
        final EditText nameEdit=view.findViewById(R.id.edt_name);
        final EditText ageEdit=view.findViewById(R.id.edt_age);
        new AlertDialog.Builder(MainActivity.this)
                .setIcon(R.mipmap.ic_launcher)
                .setTitle("请选择您的姓名年龄")
                .setView(view)

            //   多选框
          /*     .setMultiChoiceItems(aihao, null, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i, boolean b) {
                        //保存每次点击后的值
                        isChecked[i]=b;
                        if (b) {
                            Toast.makeText(MainActivity.this,
                                    "添加了" + aihao[i], Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(MainActivity.this,
                                    "  取消了" + aihao[i], Toast.LENGTH_SHORT).show();
                        }
                    }
                })*/

                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                     String name=nameEdit.getText().toString();
                     int age =Integer.parseInt(ageEdit.getText().toString());
                     Toast.makeText(MainActivity.this,
                             "  你的名字是" +name+"年龄是"+age, Toast.LENGTH_SHORT).show();
                        /*多选框
                      StringBuffer buffer=new StringBuffer();
                        for(int j=0;j<isChecked.length;j++){
                         if(isChecked[j]){
                             buffer.append(aihao[j]);
                         }
                       }
                        Toast.makeText(MainActivity.this,
                                "  你的爱好有" +buffer, Toast.LENGTH_SHORT).show();*/
                    }
                })
                /*
                单选框
                              *//*checkedItem=-1指未选状态,=0就是选中状态，默认情况下*//*
                .setSingleChoiceItems(xinbie, -1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        Toast.makeText(MainActivity.this,
                                "您的性别是"+xinbie[i],Toast.LENGTH_SHORT).show();
                    }
                })*/
                /*.setMessage("你今天生日")*/
               /* .setItems(cities, new .OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        Toast.makeText(MainActivity.this,"您居住在"+cities[i],Toast.LENGTH_SHORT).show();
                    }
                })*/

             /*   .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this,
                                "know",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNeutralButton("无所谓", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this,
                                "don't care",Toast.LENGTH_SHORT).show();
                    }
                })*/
                .create()
                 .show();

    }
}
